'use strict';

var typeList = [{ title: '行业资料', type: '1' }, { title: '政策法规', type: '2' }, { title: '信息披露', type: '3' }, { title: '保险知识', type: '4' }, { title: '实践研究', type: '5' }, { title: '专家观点', type: '6' }, { title: '研究报告', type: '7' }, { title: '行业指数', type: '8' }, { title: '合作交流', type: '9' }, { title: '院校课题', type: '10' }, { title: '研究成果', type: '11' }, { title: '课题检索', type: '12' }, { title: '行业新闻', type: '13' }, { title: '专题报道', type: '14' }, { title: '行业沙龙', type: '15' }];
var page = 1,
    defulSize = 12,
    catalIndex = 1,
    allPage = void 0;
/**
 * 页面初始化时加载 window.onload
 */
$(function () {
  toastr.options = {
    closeButton: false,
    debug: false,
    progressBar: true,
    positionClass: "toast-top-center",
    onclick: null,
    showDuration: "300",
    hideDuration: "1000",
    timeOut: "2000",
    extendedTimeOut: "1000",
    showEasing: "swing",
    hideEasing: "linear",
    showMethod: "fadeIn",
    hideMethod: "fadeOut"
  };
  //拿到页面参数
  expertArr();
});

// 专家列表数据
function expertArr() {
  $.server({ pageSize: 10, pageNum: page }, '/website/v1/lecturerList').then(function (res) {
    var expertArrList = res.result.data;
    var name = expertArrList[0].name + '/' + expertArrList[0].title + ' ' + expertArrList[0].introduction;
    $('#exportDescription').html(name);
    expert(expertArrList);
    allPage = res.result.totalPage;
    getPageNav(res.result.totalPage);
  });
}
function expert(obj) {
  var html = '',
      length = obj.length;

  for (var i = 0; i < length; i++) {
    html += ' <a href=\'expertDetail.html?id=' + obj[i].lecturerId + '\'><div class="topic-box expert-reset title-box col-md-12 col-sm-12 col-xs-12">\n     <img src=' + obj[i].avatar + '>\n      <div class="word-box">\n          <div class="name-box"><span class="name">' + obj[i].name + '/</span><span class="name-r">' + obj[i].title + '</span></div>\n          <div class="description">' + obj[i].introduction + '</div>\n      </div>\n  </div></a>';
  }
  $("#expertContent").html(html);
}

//上一页
function prevPage() {
  if (page == 1) {
    return toastr.info("没有上一页了喔~");
  }
  page--;
  serverLoad(defulSize);
}
//下一页
function nextPage() {
  if (page >= allPage) {
    return toastr.info("没有下一页了喔~");
  }
  page++;
  serverLoad(defulSize);
}

//首页
function firstPage() {
  if (page == 1) {
    return toastr.info("已经在首页了喔~");
  }
  page = 1;
  serverLoad(defulSize);
}

//尾页
function lastPage() {
  if (page == allPage) {
    return toastr.info("已经在尾页了喔~");
  }
  page = allPage;
  serverLoad(defulSize);
}
//点击分页重新加载
function reloadNews(i) {
  page = i;
  serverLoad(defulSize);
}

// 点击GO进入任一页面
function goPage() {
  var val = $("#pageVal").val();
  if (!val || val <= 0 || val > allPage) {
    return toastr.info("不存在的页面~");
  }
  if (val == page) {
    return;
  }
  page = val;
  serverLoad(defulSize);
}

// 计算分页 点击培训分类时  页面加载时都要调用
function getPageNav(totalPage) {
  var html = '';
  // const len = Math.ceil(Number(length) / Number(page));
  if(totalPage>10 && page>3){
    html+='...'
  }
  if(totalPage>10){
    for (var i = 0; i < totalPage; i++) {
      if( i >= page-3 && i< page+2){
        if(i+1 == page){
          html += "<div class='pageBox active' onclick= reloadNews(" + (i + 1) + ") > " + (i + 1) + " </div>";
        }else{
          html += "<div class=\"pageBox\" onclick= reloadNews(" + (i + 1) + ") > " + (i + 1) + " </div>";
        }
        
      } 
    }
    if(page<totalPage-3){
      html+='...'
    }
   
    if(page<totalPage-3){
      html += "<div class='pageBox' onclick= reloadNews(" + (totalPage) + ") > " + (totalPage) + " </div>";
    }
    $("#pageSizeBox").html(html);
  }else{
    for (var i = 0; i < totalPage; i++) {
      html += "<div class=\"pageBox\" onclick= reloadNews(" + (i + 1) + ") > " + (i + 1) + " </div>";
    }
    $("#pageSizeBox").html(html);
    $("#pageSizeBox>div").eq(page - 1).addClass("active");
  }
  
  
 
}